from simpy import Environment

from x_pc.core import DeviceCache, Device


class UnitBiz(DeviceCache):
    """
    工作单元设备配置 业务数据
    """
    # 编号
    id: str = None
    # 设备编号
    equ_code: str = None
    # 设备类型
    equ_type: int = None
    # 工作类型 关联wops_work_type
    work_type: int = None
    # 出入模式 1主入 2主出 3既入又出
    inout_mode: int = None
    # 是否启用 1启用 2不启用
    enable: int = None
    # 缓存数量(针对中间中转接驳环节)，为空则认为缓存不限制
    cache_num: int = None

    def __init__(self, **kwargs):
        for key in kwargs:
            if hasattr(self, key):
                setattr(self, key, kwargs[key])

    def cache_nums(self) -> int:
        """
        缓存数量
        :return:
        """
        return self.cache_num

    def __str__(self):
        return f'{self.__class__.__name__} (code={self.equ_code})'


class Unit(Device, UnitBiz):
    """
    工作单元设备配置
    """
    category: str = 'unit'

    def __init__(self, env: Environment, name: str, kwargs):
        Device.__init__(self, env, name)
        UnitBiz.__init__(self, **kwargs)

    @staticmethod
    def device_type() -> int:
        pass

    def device_code(self):
        return self.equ_code

    def loc(self):
        return self.device_code()

    def __str__(self):
        return UnitBiz.__str__(self)

    def __repr__(self):
        return self.__str__()
